import {funt} from "./ajax.js";
// const URL = "http://localhost:3000/dataAcquisition";
// const URL = "http://xuejiang.free.idcfengye.com/dataAcquisition";
const URL = "	http://xuesang.vipgz1.91tunnel.com/dataAcquisition";

function correctionURL(text) {
  let imgReg = /<img.*?(?:>|\/>)/gi //匹配图片中的img标签
  let arr = text.match(imgReg)  //筛选出所有的img
  let str = "";
  let strs = [];  
  for(const key in arr) {
    str = arr[key].slice(10);
    str = str.slice(0, arr[key].length-33);    
    str = str.replace(/ /g, "+");
    
    strs.push(str);
  }
  
  return strs;
}

function dataAcquisition() {
  var loc = location.href;
  var n1 = loc.length;
  var n2 = loc.indexOf('=');

  // var txt = decodeURI(loc.slice(n2+1));
  var txt = decodeURI(loc.substr(n2+1, n1-n2));
  console.log(txt.slice(2, -2));

  funt("post", URL, fun, "data="+txt.slice(2, -2));
  function fun(value) {    
    let arr = correctionURL(value);
    const boxs = document.getElementById("boxs");
    boxs.innerHTML = value;

    let imgs = document.getElementsByTagName("img");
    for(let i = 0; i < imgs.length; i++) {
      imgs[i].src = "";
      imgs[i].src = arr[i];
    }

  }

}

dataAcquisition(); 

